﻿using System;
using System.Collections.Generic;
using KKCai.TC.App.DAL;
using KKCai.TC.App.Model;
using Newtonsoft.Json;

namespace KKCai.TC.App
{
    public class Wapper
    {
        public IList<RecordInfo> record;

        public IList<int> count;
    }

    public class Manager
    {
        public string List(int limit)
        {
            Wapper w = new Wapper
            {
                record = new RecordDao().Order("Phase", false, limit),
                count = new DayCountDao().List()
            };

            return JsonConvert.SerializeObject(w);
        }

        public void Save(string phase, string result)
        {
            RecordDao dao = new RecordDao();
            if (dao.Get(phase) == null)
            {
                dao.Save(new RecordInfo(phase, result));

                DayCountDao ddao = new DayCountDao();
                if (1 == Convert.ToInt32(phase.Substring(phase.Length - 2)))
                    ddao.Reset();
                ddao.Update(result);
            }
        }
    }
}
